/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     string val；
 *     TreeNode *left;
 *     TreeNode *right;
 * };
 */
 // 先序遍历
class Solution {
public:
    string ans;
    string expressionTree(TreeNode* u) {
        dfs(u);
        // if(u->val[0]=='*'||u->val[0]=='/') 
            ans=ans.substr(1, ans.size()-2);
        return ans;
    }
    
    void dfs(TreeNode* u)
    {
        if(u==nullptr) return;
        if(!isdigit(u->val[0]))
        {
            ans.push_back('(');
            dfs(u->left);
            ans+=u->val;
            dfs(u->right);
            ans.push_back(')');
        }
        else ans+=u->val;  
    }
};
